package com.xz.simplerpc.console.domain;

import com.google.common.base.Joiner;
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Properties;

/**
 * Created by fingal on 2018/1/14.
 */
@Slf4j
public class Config {
    private static final String FILE_SEPARATOR = System.getProperty("file.separator");

    private static String address;

    public static String getAddress() {
        return address;
    }

    public static void load() {
        Properties props = new Properties();
        URL classLoaderURL = Thread.currentThread().getContextClassLoader().getResource("");
        String configFilePath = Joiner.on(FILE_SEPARATOR).join(classLoaderURL.getPath(), "config.properties");
        try {
            props.load(new FileInputStream(configFilePath));
        } catch (final IOException ex) {
            log.warn("Cannot found auth config file, use default auth config.");
        }
        address = props.getProperty("address", "zookeeper://127.0.0.1:2181");
    }
}
